import { http } from "@/utils/http";

/** 获取系统默认价格列表 */
export const getSystemPrices = () => {
  return http.request<any>("get", "/api/admin/prices/system");
};

/** 获取指定用户的价格配置（可按服务类型筛选） */
export const getUserPriceConfigs = (params: {
  userId: number;
  serviceType?: string;
  page?: number;
  size?: number;
  keyword?: string;
}) => {
  return http.request<any>("get", "/api/admin/config/price/user/list", {
    params
  });
};

/** 为用户创建或更新特定服务类型的价格配置 */
export const createUserPrice = (
  userId: number,
  standardCode: string,
  params: {
    price: number;
  }
) => {
  return http.request<any>(
    "post",
    `/api/admin/config/price/user/${userId}/service/${standardCode}`,
    {
      params
    }
  );
};
/** 重置用户特定价格 */
export const resetUserServicePrice = (userId: number, serviceType: string) => {
  return http.request<any>(
    "post",
    `/api/admin/config/price/user/${userId}/service/${serviceType}/reset`
  );
};

/** 批量创建或更新用户价格配置 */
export const createUserPriceBatch = (userId: number, data: object[]) => {
  return http.request<any>("post", `/api/admin/prices/user-prices/batch`, {
    params: { userId },
    data
  });
};

/** 获取指定用户指定服务类型的价格 */
export const getUserServiceTypePrice = (
  userId: number,
  serviceType: string
) => {
  return http.request<any>(
    "get",
    `/api/admin/prices/user/${userId}/${serviceType}`
  );
};

/** 删除指定的用户价格配置 */
export const deleteUserPriceConfig = (id: number) => {
  return http.request<any>("delete", `/api/admin/prices/user/${id}`);
};
/**
 * 重置用户所有价格配置
 */
export const resetUserPriceConfig = (userId: number) => {
  return http.request<any>(
    "put",
    `/api/admin/config/prices/user/${userId}/reset`
  );
};

/**
 * 批量更新多个服务类型的系统默认价格
 */
export const updateSysPricesBatch = (data: any[]) => {
  return http.request<any>("put", "/api/admin/prices/system/batch", { data });
};

/**
 * 设置单个服务类型价格
 * @param params.serviceTypeCode  服务标准代码，例如 "tg_activate"
 * @param params.price 价格（积分）
 */
export const updateSysServicePrice = (params: {
  serviceTypeCode: string;
  price: number;
}) => {
  return http.request<any>(
    "put",
    `/api/admin/service-types/${params.serviceTypeCode}/default-price`,
    {
      params: {
        price: params.price
      }
    }
  );
};

// 获取服务价格配置列表
export const getServicePriceConfigList = (params: {
  size: number;
  page: number;
  ownerId?: number;
  keyword?: string;
  serviceType?: string;
  enabled?: boolean | string;
}) => {
  return http.request<any>("get", "/api/admin/config/price/service/list", {
    params
  });
};
// 删除服务类型价格配置
export const deleteServicePriceConfig = (serviceType: string) => {
  return http.request<any>(
    "delete",
    `/api/admin/config/price/service/${serviceType}`
  );
};
// 设置服务类型价格
export const setServicePriceConfig = (
  serviceType: string,
  params: {
    price: number | string;
  }
) => {
  return http.request<any>(
    "post",
    `/api/admin/config/price/service/${serviceType}`,
    { params }
  );
};
//  批量调整某服务的用户特定价格
export const adjustUserCustomPricesByService = (
  serviceType: string,
  params: {
    delta: number | string;
  }
) => {
  return http.request<any>(
    "post",
    `/api/admin/config/price/user/service/${serviceType}/adjust`,
    { params }
  );
};
